package operation;

import book.Book;
import book.BookList;

import java.util.Scanner;

public class Borrow implements IOperation{
    @Override
    public void work(BookList bookList) {
        System.out.println("borrow book");
        Scanner scanner = new Scanner(System.in);
        System.out.print("input the name of the book you want to borrow");
        String name = scanner.nextLine();
        int index = -1;
        for (int i = 0; i < bookList.getBookNum(); i++) {
            Book book = bookList.getBook(i);
            if(book.getName().equals(name)) {
                index = i;
                break;
            }
        }
        if(index != -1) {
            if(!bookList.getBook(index).isBorrowed()) {
                bookList.getBook(index).setBorrowed(true);
            }else {
                System.out.println("the book has returned");
            }
        }else {
            System.out.println("the book is not exist");
        }

    }
}
